<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的博客平台</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Arial, sans-serif;
        }

        body {
            background: #f0f2f5;
            color: #1a1a1a;
            line-height: 1.6;
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 2rem;
        }

        .create-post {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            margin-bottom: 2rem;
        }

        .create-post input,
        .create-post textarea {
            width: 100%;
            padding: 0.8rem;
            margin-bottom: 1rem;
            border: 1px solid #e0e0e0;
            border-radius: 6px;
            font-size: 1rem;
        }

        .btn {
            background: #1877f2;
            color: white;
            border: none;
            padding: 0.8rem 1.5rem;
            border-radius: 6px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .btn:hover {
            background: #166fe5;
        }

        .posts {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }

        .post {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }

        .post h2 {
            color: #1a1a1a;
            margin-bottom: 1rem;
        }

        .post-content {
            color: #4a4a4a;
            margin-bottom: 1.5rem;
        }

        .actions {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-bottom: 1.5rem;
        }

        .like-btn {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            background: #f0f2f5;
            padding: 0.5rem 1rem;
            border-radius: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .like-btn:hover {
            background: #e4e6e9;
        }

        .comments {
            margin-top: 1.5rem;
            padding-top: 1.5rem;
            border-top: 1px solid #eee;
        }

        .comment-input {
            display: flex;
            gap: 1rem;
            margin-top: 1rem;
        }

        .comment-input input {
            flex: 1;
            padding: 0.8rem;
            border: 1px solid #e0e0e0;
            border-radius: 6px;
        }

        .comment {
            background: #f5f6f7;
            padding: 1rem;
            border-radius: 6px;
            margin-top: 1rem;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="create-post">
            <h1>写新博客</h1>
            <input type="text" id="postTitle" placeholder="博客标题">
            <textarea id="postContent" rows="4" placeholder="写下你的想法..."></textarea>
            <button class="btn" onclick="createPost()">发布</button>
        </div>

        <div class="posts" id="postsContainer"></div>
    </div>

    <script>
        // 初始化本地存储
        let posts = JSON.parse(localStorage.getItem('posts')) || [];

        // 创建新博客
        function createPost() {
            const title = document.getElementById('postTitle').value;
            const content = document.getElementById('postContent').value;

            if (title && content) {
                const newPost = {
                    id: Date.now(),
                    title,
                    content,
                    likes: 0,
                    comments: []
                };

                posts.unshift(newPost);
                savePosts();
                renderPosts();
                document.getElementById('postTitle').value = '';
                document.getElementById('postContent').value = '';
            }
        }

        // 点赞功能
        function likePost(postId) {
            const post = posts.find(p => p.id === postId);
            post.likes++;
            savePosts();
            renderPosts();
        }

        // 添加评论
        function addComment(postId, input) {
            const comment = input.value;
            if (comment) {
                const post = posts.find(p => p.id === postId);
                post.comments.push(comment);
                input.value = '';
                savePosts();
                renderPosts();
            }
        }

        // 保存到本地存储
        function savePosts() {
            localStorage.setItem('posts', JSON.stringify(posts));
        }

        // 渲染博客
        function renderPosts() {
            const container = document.getElementById('postsContainer');
            container.innerHTML = '';

            posts.forEach(post => {
                const postElement = document.createElement('div');
                postElement.className = 'post';
                postElement.innerHTML = `
                    <h2>${post.title}</h2>
                    <div class="post-content">${post.content}</div>
                    <div class="actions">
                        <div class="like-btn" onclick="likePost(${post.id})">
                            👍 ${post.likes}
                        </div>
                    </div>
                    <div class="comments">
                        <h3>评论 (${post.comments.length})</h3>
                        ${post.comments.map(comment => `
                            <div class="comment">${comment}</div>
                        `).join('')}
                        <div class="comment-input">
                            <input type="text" 
                                   placeholder="写下你的评论..." 
                                   onkeypress="if(event.key === 'Enter') addComment(${post.id}, this)">
                            <button class="btn" onclick="addComment(${post.id}, this.previousElementSibling)">提交</button>
                        </div>
                    </div>
                `;
                container.appendChild(postElement);
            });
        }

        // 初始化渲染
        renderPosts();
    </script>
</body>
</html>
